package com.karson.common.enums;

import com.karson.common.request.FileRequest;

public enum FileCategory {
    AUDIO,
    SUBTITLE,
    IMAGE,
    OTHER;

    public static FileCategory detect(FileRequest file) {
        String contentType = file.getFileType(); // eg. "application/octet-stream"
        String fileName = file.getFileName().toLowerCase();

        // 先根据 Content-Type 判断
        if (contentType != null) {
            if (contentType.startsWith("audio/")) {
                return AUDIO;
            } else if (contentType.startsWith("image/")) {
                return IMAGE;
            } else if (contentType.equals("text/vtt")) {
                return SUBTITLE;
            }
        }

        // 根据文件后缀判断
        if (fileName.endsWith(".srt") || fileName.endsWith(".vtt") || fileName.endsWith(".ass")) {
            return SUBTITLE;
        }

        return OTHER;
    }
}
